T=0
while (T<=0 or T>30):
 T=input("Enter No of tests")
k=1
while (k<=T):
 N=0
 while (N<=0 or N>100):
   N=input("No of list items")
 l=[]
 for i in range (0,N):
  x=0
  while (x<1 or x>10000):
   x=input("Enter element:")
   l.append(x) 
 count=1
 for i in l:
	flag=1

	for j in range(2,(i/2)+1):
		if i%j==0 and i!=2:
			flag =0
    if flag==1 and i!=1 and count==1:
		max=min=i		
	 	count=count+1
    if flag==1 & i!=1 and count!=1:			
			if (max<i):
			    max=i
			if (min>i):
			    min=i		
 print max
 print min
 k=k+1